cc.Class({
    extends: cc.Component,

    properties: {
        brush: cc.Node,
    },

    onLoad() {      
        console.log("chen drawboard onLoad")
        
    },

    start() {
        this.drawInfo = {
            "lineWidth": 5,
            "color": "BLACK",
            "x0": 0,
            "y0": 0,
            "x1": 0,
            "y1": 0,
        }
        this.brushBottomLine = (this.brush.getPosition())
        console.log("chen brushBottomLine",this.brushBottomLine)
    

        this.drawInfo.lineWidth = 5

        this.node.on('touchstart', this.onTouchStart, this);
        this.node.on('touchmove', this.onTouchMove, this);
    },

    onTouchStart(event) {
        // 设置笔刷起始位置
        let pos = this.node.convertToNodeSpaceAR(event.getLocation());
        this.drawInfo.x0 = pos.x
        this.drawInfo.y0 = pos.y
    },

    onTouchMove(event) {
        if (this.brush == null) {
            return
        }
        let pos = this.node.convertToNodeSpaceAR(event.getLocation());
        console.log("onTouchMove| pos.x:", pos.x, "gpos.y:", pos.y)
        
        this.drawInfo.x1 = pos.x
        // 画板底部边界
        this.drawInfo.y1 = pos.y < 0 ? 0 :pos.y 
        
        

        this.brush.getComponent('Brush').doDraw(this.drawInfo.x0, this.drawInfo.y0, this.drawInfo.x1, this.drawInfo.y1, this.drawInfo.color, this.drawInfo.lineWidth);

        // 更新起始位置
        this.drawInfo.x0 = this.drawInfo.x1
        this.drawInfo.y0 = this.drawInfo.y1
    },

    // update (dt) {},
});
